//
//  EPMRightTableView.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/5/1.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMRightTableView.h"
#import "EPMRightTableViewCell.h"
#import "EPMRightLastTableViewCell.h"
#import "EPMCategoryModel.h"



@interface EPMRightTableView()<UITableViewDelegate,UITableViewDataSource>


@property (assign,nonatomic) CGPoint startPoint;
@property (assign,nonatomic) BOOL isUP;
@property (strong,nonatomic) NSArray* goodsList;
@end
@implementation EPMRightTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    if (self = [super initWithFrame:frame style:style]){
        [self settings];
    }
    return self;
}

#pragma mark - 参数设置 -

- (void)settings{
    self.dataSource = self;
    self.delegate = self;
    [self registerNib:[UINib nibWithNibName:@"EPMRightTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell"];
    [self registerClass:[EPMRightLastTableViewCell class] forCellReuseIdentifier:@"last"];
    
    self.estimatedRowHeight = 100;
    self.sectionHeaderHeight = 43;
    
   [_MarketManger setMarketDisPlayListBlock:^(NSArray * goodList) {
       self.goodsList = goodList;
       [self reloadData];
   }];
    
  

   
}




#pragma mark - 数据源方法 -

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.goodsList.count + 1 ;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.item == self.goodsList.count){
        EPMRightLastTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"last" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }
    
    EPMRightTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.backgroundColor = [UIColor randomColor];
    EPMGoodsModel* model = self.goodsList[indexPath.row];
    cell.model = model;
    cell.indexpath = indexPath;
    [cell setMaketRightCellBtnClickBlock:^(NSIndexPath *indexpath) {
       
       
        
       
    }];
    return cell;
}

#pragma mark - 代理方法 -

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  
    if (self.startPoint.y <= scrollView.contentOffset.y && scrollView.contentOffset.y >0 )
    {
        //上翻
        self.isUP = YES;
        
    }else if (self.startPoint.y > scrollView.contentOffset.y && scrollView.contentOffset.y <= 0){
        self.isUP = NO;
    }
    
    if (self.rightTableViewPulling){
        self.rightTableViewPulling(self.isUP);
    }
    
    
      self.startPoint = scrollView.contentOffset;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

@end
